package com.weiyi.weiman.api;

import com.weiyi.weiman.domain.dto.CategoryDTO;
import com.weiyi.weiman.domain.dto.ResultInfo;
import com.weiyi.weiman.service.comics.ComicsListService;
import com.weiyi.weiman.utils.ResultUtils;
import comics.Category;
import comics.ComicsRank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author zhang
 * @Date 2021/5/13 下午2:22
 * @Description 展示漫画列表的控制类
 * @Version 1.0
 **/
@RestController
@RequestMapping("/comics")
public class ComicsListController {

    @Autowired
    private ComicsListService comicsListService;

    /**
     * 获取漫画分类列表
     * @return
     */
    @GetMapping("/categoryList")
    public ResultInfo getCategoryList() {
        List<Category> list = null;
        try {
            list = comicsListService.getCategoryList();
        } catch (Exception e) {
            e.printStackTrace();
            ResultUtils.failureInfo(e.getMessage());
        }
        return ResultUtils.successInfo(list);
    }

    /**
     * 获取漫画排名列表
     * @return
     */
    @GetMapping("/rankList")
    public ResultInfo getRankList() {
        List<ComicsRank> list = null;
        try {
            list = comicsListService.getRankList();
        } catch (Exception e) {
            e.printStackTrace();
            ResultUtils.failureInfo(e.getMessage());
        }
        return ResultUtils.successInfo(list);
    }

}
